package com.supermap.search.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.supermap.search.R;
import com.supermap.search.Url_name;
import com.supermap.search.javabean.XunJianImg;
import com.supermap.search.javabean.XunJianJiLu;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.rest.RequestQueue;
import com.yolanda.nohttp.rest.Response;
import com.yolanda.nohttp.rest.SimpleResponseListener;
import com.yolanda.nohttp.rest.StringRequest;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wyw on 2017/3/8.
 * 已上传巡检记录详情的页面
 */

public class YiShangChuanXiangQingActivity extends AppCompatActivity {


    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_chengdu)
    TextView tvChengdu;
    @BindView(R.id.tv_wentiqingkuang)
    TextView tvWentiqingkuang;
    @BindView(R.id.ll_photo)
    LinearLayout llPhoto;
    private XunJianJiLu.ResultListBean ResultListBean;
    private RequestQueue requestQueue;
    private StringRequest stringRequestimg;
    private XunJianImg xunJianImg;
    private Gson gson;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wentixiangqing);
        requestQueue = NoHttp.newRequestQueue();
        ButterKnife.bind(this);
        Intent intent = this.getIntent();
        ResultListBean = (XunJianJiLu.ResultListBean)intent.getSerializableExtra("user");
        tvTime.setText(ResultListBean.getREPORTTIME());
        tvChengdu.setText(ResultListBean.getSEVERITYLEVEL());
        tvWentiqingkuang.setText(ResultListBean.getPROBLEMDESC());
        stringRequestimg = new StringRequest(Url_name.IMG_XUNJIAN + ResultListBean.getPKID());
        requestQueue.add(1, stringRequestimg, new SimpleResponseListener<String>() {
            @Override
            public void onSucceed(int what, Response<String> response) {
                gson = new Gson();
                xunJianImg = gson.fromJson(response.get(), XunJianImg.class);
                //有图片时候动态加载图片
                if (xunJianImg.getResultList() != null && xunJianImg.getResultList().size() > 0) {
                    for (int i = 0;i<xunJianImg.getResultList().size();i++){
                        ImageView imageView = new ImageView(YiShangChuanXiangQingActivity.this);
                        llPhoto.addView(imageView,800,1000);
                        Glide.with(YiShangChuanXiangQingActivity.this)
                                .load(Url_name.IMG_REAL_XUNJIAN +xunJianImg.getResultList().get(i).getAttachementID())
                                .placeholder(R.mipmap.image_loading) //设置占位图
                                .thumbnail(0.1f)
                                .error(R.mipmap.image_loading_error)//加载失败时显示的图片
                                .into(imageView);
                    }
                }
            }

            @Override
            public void onFailed(int what, String url, Object tag, Exception exception, int responseCode, long networkMillis) {

            }
        });
    }
}
